package com.local.cart.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;

/**
 * rabbitmq声明
 */

@Configuration
public class RabbitMQConfig {

    @Value("${rabbitmq.cart-delete-exchange}")
    private String cartDeleteExchange;

    @Value("${rabbitmq.cart-delete-queue}")
    private String cartDeleteQueue;

    @Value("${rabbitmq.cart-delete-routingkey}")
    private String cartDeleteRoutingKey;


    /**
     * 声明交换机
     * @return
     */
    @Bean
    public TopicExchange cartDeleteExchange() {
        return new TopicExchange(this.cartDeleteExchange);
    }


    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue cartDeleteQueue() {
        return new Queue(this.cartDeleteQueue);
    }


    /**
     * 交换机和队列绑定
     * @return
     */
    @Bean
    public Binding bindQueue(Queue cartDeleteQueue, TopicExchange cartDeleteExchange) {
        return BindingBuilder.bind(cartDeleteQueue)
                .to(cartDeleteExchange)
                .with(this.cartDeleteRoutingKey);
    }


}
